﻿package com.wxsoft.business.sys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.wxsoft.business.model.easyui.PageHelper;
import com.wxsoft.business.sys.dao.ISysMenuDao;
import com.wxsoft.business.sys.dao.ISysUserDao;
import com.wxsoft.business.sys.pojo.SysMenu;
import com.wxsoft.business.sys.pojo.SysUser;
import com.wxsoft.business.sys.service.ISysUserService;

@Service("sysUserService")
public class SysUserServiceImpl implements ISysUserService  {
	@Resource
	private ISysUserDao dao;
	
	@Autowired
	private ISysMenuDao sysMenuDao;
	
	
	public long findCount(SysUser sysUser) {
		return dao.findCount(sysUser);
	}
	
	public List<SysUser> findAll(PageHelper page,SysUser sysUser) {
        List<SysUser> r = dao.findAll(page,sysUser);
		return r;
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
	public String add(SysUser sysUser) {
		this.dao.insert(sysUser);
		return "操作成功!";
	}
	
	public String modify(SysUser sysUser) {
		this.dao.modify(sysUser);
		return "操作成功!";
	}
	
	public String delete(SysUser sysUser) {
		this.dao.delete(sysUser);
		return "操作成功!";
	}
	/**
	 * 
	 * @param username
	 * @return
	 */
	public SysUser findUserByName(String username) {

		SysUser user = new SysUser();
		user.setUser_name(username);
		return dao.findUserByName(user);
	}
	/**
	 * 获取该用户权限的菜单
	 * @param userId
	 * @return
	 */
	public List<SysMenu> getMenu(String userId) {
		return sysMenuDao.getMenuByUserId(userId);  
	}
	
}
